import java.io.FileNotFoundException;
import java.io.IOException;

class MyException extends Exception{
    public MyException() {
        super();
    }
    public MyException(String message) {
        super(message);
    }
}

class UserException extends Exception {
    public UserException(String message) {
        super(message);
    }
}
class PasswordException extends Exception {
    public PasswordException(String message) {
        super(message);
    }
}


public class TestDemo{

    private static String userName = "admin";
    private static String password = "123456";

    public static void login(String userName, String password) throws UserException,
            PasswordException {
        if (!TestDemo.userName.equals(userName)) {
            throw new UserException("用户名错误");
        }
        if (!TestDemo.password.equals(password)) {
            throw new PasswordException("密码错误");
        }
        System.out.println("登陆成功");
    }

    public static void main(String[] args) {
        try {
            login("admin", "123456");
        } catch (UserException userError) {
            userError.printStackTrace();
        } catch (PasswordException passwordError) {
            passwordError.printStackTrace();
        }
    }

    public static void func2() throws MyException{
        int a = 10;
        if(a == 10) {
            throw new MyException("异常出错的信息");
        }
    }

    public static void main3(String[] args) throws  MyException{
        func2();

        /*try {
            func2();
        }catch (MyException e) {

        }*/
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public static void func() throws RuntimeException,NullPointerException{

        int a = 10;
        if(a == 10) {
            throw new RuntimeException("a == 10");
        }
    }
    public static void main2(String[] args) {
        try {
            func();
        }catch (RuntimeException e) {
            System.out.println("抛出了一个异常！");
        }
        System.out.println("fdsafdsaf");
    }


    private static void testMethod(){

        System.out.println("testMethod");

    }
    public void getCustomerInfo() {

        try {

            // 这里可能会抛出异常-》不会执行try剩下的代码了
            throw new Exception();
            //dsfafadsa
        } catch (java.io.FileNotFoundException ex) {

            System.out.print("FileNotFoundException!");

        } catch (java.io.IOException ex) {

            System.out.print("IOException!");

        } catch (java.lang.Exception ex) {

            System.out.print("Exception!");

        }
    }

    public void getCustomerInfo2() {

        try {

            // 这里可能会抛出异常-》不会执行try剩下的代码了
            throw new IOException();
            //dsfafadsa
        } catch (java.lang.Exception ex) {

            System.out.print("Exception!");

        }/* catch (java.io.IOException ex) {

            System.out.print("IOException!");

        }catch (java.io.FileNotFoundException ex) {

            System.out.print("FileNotFoundException!");

        } */
    }
}
